/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game.source.gui.menu;

import game.source.gui.GameFrame;
import game.source.gui.ship.GuiPlayerShip;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;

/*MenuCreditos:
 *	Exibe os créditos do jogo
 */
public class MenuCreditos extends JPanel {

    private JButton			bvoltar;
    private JPanel			pbotoes;
    private BufferedImage	img;
    private GameFrame		frame;
    private Font			font;
    private Font			font2;

    public MenuCreditos(GameFrame frameup) {

        this.bvoltar	= new JButton("VOLTAR");
        this.pbotoes	= new JPanel();
        this.font		= new Font("Algerian", Font.PLAIN, 20);
        this.font2		= new Font("Comic Sans Ms", Font.PLAIN, 20);
        this.frame		= frameup;
        this.bvoltar.addActionListener(new OuvinteBotao(this.frame));
        this.bvoltar.setSize(20, 20);
        this.bvoltar.setFocusable(false);
        this.bvoltar.setFont(font);
        this.pbotoes.setBackground(new Color(0, 0, 0, 0));
        this.pbotoes.setLayout(new FlowLayout(FlowLayout.RIGHT));
        this.pbotoes.add(bvoltar);

        try {
            this.img = ImageIO.read(new File(MenuCreditos.class.getResource("/images/menus/afeganistan.png").getFile()));
        } catch (Exception e) {
        	e.printStackTrace();
            System.err.println("Arquivo: " + MenuCreditos.class.getResource("/images/menus/afeganistan.png") + " não pode ser aberto");
            System.exit(1);
        }

        this.setLayout(new BorderLayout());
        this.add(pbotoes, "South");
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D graphics = (Graphics2D)g;
        int x = (this.getWidth() - this.img.getWidth(null)) / 2;
        int y = (this.getHeight() - this.img.getHeight(null)) / 2;
        graphics.drawImage(this.img, x, y, this);
        graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        graphics.setFont(this.font2);
        graphics.setColor(new Color(0));
        int line = graphics.getFontMetrics().getHeight();
        graphics.drawString("Game Air Hunter - Trabalho de Programação Orientada a Objetos",80,80);
        graphics.drawString("Engenharia de Computação - Novembro de 2011 - prof. Fernando Paulovich",80,80+line);
        graphics.drawString("Desenvolvedores: João Donato da Silva Petroni",80,80+2*line);
        int space = graphics.getFontMetrics().stringWidth("Desenvolvedores: ");
        graphics.drawString("Murilo Alencar Alves Júnior",80+space,80+3*line);
        graphics.drawString("Sons: Tiro: http://www.freesound.org/people/junggle/sounds/28917/",80,80+4*line);
        space =  graphics.getFontMetrics().stringWidth("Sons: ");
        graphics.drawString("Explosão: http://soundbible.com/1807-Explosion-Ultra-Bass.html",80+space,80+5*line);
    }

    class OuvinteBotao implements ActionListener {

        private GameFrame frame;

        public OuvinteBotao(GameFrame frameup) {
            this.frame = frameup;
        }

        public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == bvoltar){
                this.frame.remove(frame.getMenuCreditos());
                this.frame.setGameMenu(new GameMenu(this.frame));
                this.frame.add(this.frame.getGameMenu());
                this.frame.start();
            }
        }
    }
}
